<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <script src="../js/jweixin-1.2.0.js"></script>
    <script src="../js/config.js"></script>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=Xyiagrrc6TszGnVTxdlDdzp4uj2UkfTj"></script>
    <script>
        var xx;
        var yy;
        $.getJSON("/map/getConfig/", function (json) {
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: configAppId, // 必填，公众号的唯一标识
                timestamp: json.timeStamp, // 必填，生成签名的时间戳
                nonceStr: json.nonceStr, // 必填，生成签名的随机串
                signature: json.signature,// 必填，签名
                jsApiList: [
                    'openLocation',
                    'getLocation'
                ] // 必填，需要使用的JS接口列表，所有JS接口列表见官方文档附录2
            });
            wx.ready(function () {
                var Reqx;
                var Reqy;
                var openId;
                var doEventId;
                var eventName;
                var eventID;
                date = new Date();
                var userId;
                var nowDate = date.toLocaleDateString();
                bm = new BMap.Map("allmap");
                getLocation();
                //alert("nowDate is :"+nowDate);
                console.log("this is ready");
                $.getJSON("/map/getOpenId/", function (json) {
                    openId = json.openId;
                    //alert("openId|" + openId);
                    var nowTime = new Date();
                    var user = {openId: openId};
                })
            })
            function getLocation() {
                wx.getLocation({

                    type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                    success: function (res) {
                        console.log("this is get location=========" + res.latitude);
                        console.log("this is get location=========" + res.longitude);
                        xx = res.longitude;
                        yy = res.latitude;


                    }, cancel: function (res) {

                    }
                });
            };

        })



        $(document).ready(function () {
            $("#btn_submit").click(function () {
                var location={
                    name:$("#place").val(),
                    x:xx,
                    y:yy
                }
                $.ajax({
                    type:"post",
                    data:location,
                    dataType:"text",
                    async:false,
                    url:"/location/add",
                    success:function (data) {
                        alert("上传成功！");
                    },
                    error:function () {
                        alert("上传失败！");
                    }
                })
            });


        });
    </script>
</head>
<body>
<div id="map_canvas">
</div>
<div align="center">
<input type="text" id="place" />
<button type="button" class="btn btn-primary" id="btn_submit">上传</button>
    </div>
</body>
</html>